package com.gexin.controller.system.product;

import com.gexin.core.web.SystemBaseController;
import com.gexin.model.product.ProductType;
import com.gexin.model.shop.ShopInfo;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.log.Log;

import java.util.List;

/**
 * 话题
 * @author 方俊逸
 *  2016-05-12
 *
 */

@ControllerBind(controllerKey = "/system/productType", viewPath = "WEB-INF/system/product")
public class ProductTypeController extends SystemBaseController {
	private static Log log = Log.getLog(ProductTypeController.class);
	public void index(){
		log.info("商品种类");
	    setAttr("shopid", ShopInfo.shop_id);
		List<ProductType>  type_list= ProductType.dao.findAllByShopId(String.valueOf(ShopInfo.shop_id));
		setAttr("type_list", type_list);
		render("productType.html");
	}
	
	/**
	 * ajax  增加保存
	 */
	public void add_save(){
		ProductType type=new ProductType();
		type.setTypeName(getPara("title").trim());
		type.setSort(Integer.parseInt(getPara("sort").trim()));
		type.setShopId(String.valueOf(ShopInfo.shop_id));
		if(type.save()){
			success();
		}
		else{
			fail();
		}
	}
	
	/**
	 * ajax  修改保存
	 */
	public void edit_save(){
		ProductType type= ProductType.dao.findById(getPara("id"));
		type.setTypeName(getPara("name").trim());
		type.setShopId(String.valueOf(ShopInfo.shop_id));
		type.setSort(Integer.parseInt(getPara("sort").trim()));
		if(type.update()){
			success();
		}
		else{
			fail();
		}
	}
	
	
	/*
	 * 删除
	 * 就是将状态改为1
	 */
	public void delete(){
		ProductType type= ProductType.dao.findById(getPara());
		type.setState(1);//禁用
		if(type.update()){
			success();
		}
		else{
			fail();
		}
	}
    //开启
	public void start(){
		ProductType type= ProductType.dao.findById(getPara("id"));
		type.setState(0);//启用
		if(type.update()){
			success();
		}
		else{
			fail();
		}
	}

	
	
}


